/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * <p>Project: javase - Reg4
 * <p>Powered by webrx On 2021-12-06 15:25:56
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Reg4 {
    public static void main(String[] args) {
        //java.util.regex.Pattern
        //var p1 = Pattern.compile("\\d");
        var p1 = Pattern.compile("[a-z]{1,}");

        //var p2 = Pattern.compile("[a-zA-Z]{1,}");
        var p2 = Pattern.compile("[a-z]{1,}", Pattern.CASE_INSENSITIVE);
        //var p2 = Pattern.compile("[a-z]{1,}", 2);

        //输出正则表达式，字符串
        //System.out.println(p1);
        //System.out.println(p1.toString());
        //System.out.println(p1.pattern());


        //java.util.regex.Matcher
        var matcher = p2.matcher("java123mysql8html5javascript-Book-student");
        while (matcher.find()) {
            System.out.printf("%s%n", matcher.group());
        }

        //123456789
        //12+3+4+56-7-8-9 = 100
        Set<String> set = new HashSet<String>();
        int index = 0;
        while (true) {
            String[] s1 = {"", "+", "-"};
            Random rand = new Random();
            StringBuilder sbu = new StringBuilder("1");
            for (int i = 2; i <= 9; i++) {
                sbu.append(s1[rand.nextInt(s1.length)]);
                sbu.append(i);
            }
            //System.out.printf("%s%n", sbu);
            var p3 = Pattern.compile("[+-]*[0-9]+");
            var m3 = p3.matcher(sbu);
            int sum = 0;
            while (m3.find()) {
                int num = Integer.parseInt(m3.group());
                sum += num;
            }
            if (sum == 100 && !set.contains(sbu.toString())) {
                System.out.printf("%d、%s = 100%n", ++index, sbu);
                set.add(sbu.toString());
            }
            if (set.size() == 11) {
                break;
            }
        }
        for (String s : set) {
            System.out.printf("%s = 100%n", s);
        }

    }
}
